﻿//6.Write a program that reads two integer numbers N and K and an array of N elements from the console. 
//Find in the array those K elements that have maximal sum.

using System;

class MaximalSum
{
    static void Main()
    {
        int numberN = int.Parse(Console.ReadLine());
        int numberK = int.Parse(Console.ReadLine());
        int[] arrayN = new int[numberN];
        int indexArray = 0;
        int maximal = int.MinValue;
        for (int i = 0; i < arrayN.Length; i++)
        {
            arrayN[i] = int.Parse(Console.ReadLine());
            if (arrayN[i] > maximal)
            {
                maximal = arrayN[i];
                indexArray = i;
            }
        }
        Console.WriteLine("arrayN[{0}]={1}", indexArray, maximal);

        for (int i = 0; i < numberK - 1; i++)
        {
            int secondMax = int.MinValue;
            int secondIndex = 0;
            for (int j = 0; j < arrayN.Length; j++)
            {
                if (secondMax < maximal && arrayN[j] > secondMax)
                {
                    secondMax = arrayN[j];
                    secondIndex = j;
                }
                else if (arrayN[j] == maximal && indexArray < j)
                {
                    secondMax = arrayN[j];
                    secondIndex = j;
                    break;
                }
            }
            Console.WriteLine("arrayN[{0}]={1}", secondIndex, secondMax);
            indexArray = secondIndex;
            maximal = secondMax;
        }
    }
}
